package com.fs.adapters;

import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageButton;
import android.widget.TextView;

import com.example.studentmanagersystem.AdminAccountActivity;
import com.example.studentmanagersystem.R;
import com.fs.myview.UpdateGradeDiaolog;
import com.fs.myview.UserListDialog;
import com.fs.po.StuSocre;

/**
 * 老师修改学生成绩适配器
 * @author chenwenfei
 *
 */
public class TecUpdateGradeAdapter extends BaseAdapter {

	private Context context;
	private List<StuSocre> scoreList;
	private int len=0;
	
	private Handler handler;
	
	public TecUpdateGradeAdapter(Context context) {
		this.context=context;
	}
	
	public void setAdapterData(List<StuSocre> scoreList,Handler handler) {
		this.scoreList=scoreList;
		this.len=scoreList.size();
		this.handler=handler;
		System.out.println("List长度"+len);
		
	}

	
	@Override
	public int getCount() {
		return len;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View view, ViewGroup parent) {
		
		ViewHolder viewHolder=null;
		if(view==null){
			view = ((Activity) context).getLayoutInflater().inflate(R.layout.teacher_updategrade_tab, null);
			viewHolder = new ViewHolder();// 创建内部类对象，保存列表项中子控件的引用；
			
			viewHolder.stuText=(TextView) view.findViewById(R.id.teacher_upgrade_tab_name);
			viewHolder.gradeText=(TextView) view.findViewById(R.id.teacher_upgrade_tab_grade);
			viewHolder.imageButton=(ImageButton) view.findViewById(R.id.teacher_upgrade_tab_imagebtn);
			
			view.setTag(viewHolder);
		}else if (view != null) {
			   viewHolder=(ViewHolder) view.getTag();
		  }
		
		viewHolder.imageButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				updateGradeDiaolog=new UpdateGradeDiaolog(context,handler);
				
				updateGradeDiaolog.showDialog(scoreList.get(position));
				
			}
		});
		
			viewHolder.stuText.setText(""+this.scoreList.get(position).getName());
			viewHolder.gradeText.setText(""+this.scoreList.get(position).getScore());
			
			return view;
	}
	
	  class ViewHolder {
		  TextView stuText;
		  TextView gradeText;
		  ImageButton imageButton;
		 }

	  
	  /**
	   * 当点击修改成绩按钮时，弹出对话框
	   */
	  UpdateGradeDiaolog updateGradeDiaolog;
	  
	
}
